<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
</head>
<body>

<div>
    <form>
        <table align="center" style="margin-top: 20%">
            <tr>
                <td><span>邮箱</span></td>
                <td><input type="text" id="email" name="email"></td>
            </tr>
            <tr>
                <td><span>密码</span></td>
                <td><input type="password" id="password" name="password"></td>
            </tr>
            <tr>
                <td><span>确认密码</span></td>
                <td><input type="password" id="confirmPassword" name="confirmPassword"></td>
            </tr>
            <tr>
                <td><span>验证码</span></td>
                <td><input type="text" id="code" name="code"></td>
                <td >
                    <a id="createCode" style="color: green;text-decoration:none;" href="javascript:void(0);">获取验证码</a>
                </td>
            </tr>
            <tr bgcolor="green" id="register">
                <td colspan="2" align="center">
                    <label style="color: white">注&nbsp;&nbsp;册</label>
                </td>
            </tr>

        </table>
    </form>
</div>

</body>

<script src="jquery-1.9.1.min.js"></script>
<script>
    console.log("初始化1");
    $(function () {
        register.init();
    });

    let register = {
        init:function () {
            console.log("初始化");
            $('#createCode').click(function () {
                console.log("获取验证码");
                $.ajax({
                   url:'/api/code/create',
                   type:'post',
                   dataType:'json',
                   data:{
                       'email':$('#email').val()
                   },
                   success:function(data) {
                       if (data.code == 200) {
                           alert('验证码发送成功，请到邮箱查看');
                       } else {
                           alert(data.message);
                       }
                   }
                });
            });

            $('#register').click(function () {
                $.ajax({
                   url: '/api/user/register',
                   type:'post',
                   dataType:'json',
                   data:{
                       'email':$('#email').val(),
                       'password':$('#password').val(),
                       'confirmPassword':$('#confirmPassword').val(),
                       'code':$('#code').val()
                   } ,
                    success:function (data) {
                        if (data.code == 200) {
                            window.location = "/static/login.html";
                        } else {
                            alert(data.message);
                        }
                    }
                });
            })
        },
    };

</script>
</html>

